//按下鼠标之后
$(function(){
    $('.ditu').mousedown(function(){
        $(this).addClass('add1');
    });
//松开鼠标之后
    $('.ditu').mouseup(function(){
        $(this).removeClass('add1');
    });
    //随机 函数
    function GetRandomNum(Min,Max){
        var Range = Max - Min;
        var Rand = Math.random();
        return(Min + Math.round(Rand * Range));
    };
    //遍历 出现与消失 位置
    function show(){
        var index = GetRandomNum(0,8);
        $('.box').eq(index).find('img').animate({marginTop:0},200)
        setTimeout(hide,3000);
        function hide(){
            $('.box').eq(index).find('img').animate({marginTop:'80px'},200)
        };
    };
    //点击（敲打）成功后 计分板获得分数
    $('.box img').click(function(){
        var n = Number($('#valScore').val());
        $(this).animate({marginTop:'80px'},200);
        n++;
        $('#valScore').val(n)
        //得分
        $('.score').html(n);
    });

    //开始游戏
    $('.start').click(function(){
        $('.box_win').hide();
        $('.text').hide();
        var diff = Number($('#selDiff').val());
        var t = Number($('#selTime').val());
        var start = setInterval(time,1000);
        var num = setInterval(show,diff*1000);
        var n2 = t/diff/3*2;
        $('.time').html(t);
        $('#valScore').val('0');
        $('.score').html('0');
        var a=Number($('.time').html());
        function time(){
            a--;
            if(a < 0){
                clearInterval(start);
                clearInterval(num);
                var grade = '';
                var n = Number($('#valScore').val());
                var n3 = t/diff;
                var n2 = t/diff/3*2;
                var n1 = t/diff/3;
                if(n == 0){
                    grade = '搞个铲铲哦！'
                }
                if(n>0 && n<n1){
                    grade = '有点笨！'
                }
                if(n>=n1 && n<n2){
                    grade = '不错！'
                }
                if(n>=n2 && n<n3){
                    grade = '很棒！'
                }
                if(n == n3){
                    grade = '完美！'
                }
                $('.box_win').show();
                $('.win_score').show();
                $('.cj').html('GameOver，您一共得了'+n+'分，'+grade);
            }else{
                $('.time').html(a);
            }
        };

    });

    $('.again').click(function(){
        $('.start').click();
        $('.win_score').hide();
    });
    $('.close').click(function(){
        window.close();
    });

});